package com.zzyl.nursing.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.exception.base.BaseException;
import com.zzyl.nursing.domain.NursingTask;
import com.zzyl.nursing.dto.EstimatedServerTimeDto;
import com.zzyl.nursing.dto.NursingTaskDto;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import com.zzyl.nursing.dto.CancelDto;
import com.zzyl.nursing.dto.PerformTasksDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.nursing.service.INursingTaskService;

/**
 * 护理任务Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/nursing/nursingTask")
@Api(tags = "护理任务的接口")
public class NursingTaskController extends BaseController
{
    @Autowired
    private INursingTaskService nursingTaskService;
    @GetMapping("/list")
    public TableDataInfo list(NursingTaskDto nursingTaskDto){
        startPage();
        List<NursingTask> list = nursingTaskService.selectNursingTaskList(nursingTaskDto);
        return getDataTable(list);
    }
    @GetMapping("{id}")
    public AjaxResult getDetail(@PathVariable("id") Integer id){
        try {
            return success(nursingTaskService.selectNursingTaskDetailById(id));
        }catch (Exception e){
            throw new BaseException("您保存的信息不完整");
        }
    }
    @PutMapping("/updateTime")
    public AjaxResult updateTime(@RequestBody EstimatedServerTimeDto estimatedServerTimeDto){
        return toAjax(nursingTaskService.update(Wrappers.<NursingTask>lambdaUpdate().eq(NursingTask::getId,estimatedServerTimeDto.getTaskId())
                .set(NursingTask::getEstimatedServerTime,estimatedServerTimeDto.getEstimatedServerTime())));
    }
    @Qualifier("nursingTaskServiceImpl")


  /*  *//**
     * 获取护理任务详细信息
     *//*
    @ApiOperation("获取护理任务详细信息")
    @PreAuthorize("@ss.hasPermi('nursing:nursingTask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(value = "护理任务ID", required = true)
            @PathVariable("id") Long id)
    {
        NursingTaskUpVo vo = nursingTaskService.selectNursingTaskById(id);
        return success(vo);
    }*/

    /**
     * 取消任务
     */
    @ApiOperation("取消任务")
    @PutMapping(value = "/cancel")
    public AjaxResult cancel(@RequestBody CancelDto dto)
    {
        nursingTaskService.cancel(dto);
        return success();
    }
    /**
     * 执行任务
     */
    @ApiOperation("执行任务")
    @PutMapping(value = "/do")
    public AjaxResult performTasks(@RequestBody PerformTasksDto dto)
    {
        nursingTaskService.performTasks(dto);
        return success();
    }

}
